const fs = require('fs');
const path = require('path');


const dataFilePath = path.join(__dirname, 'data/');
const dataMap = {
  "无法停车": "car.json",
  "股市大跌": "stock.json",
  "美联储加息": "ustb.json",
  "货币超发": "currency.json",
  "联合登岛作战": "join-amphibious-operation.json",
  "红色方电子战": "military-event-entity-relation.json",
  "交通拥堵": "traffic-jam.json",
  "补给线阻塞": "route-jam.json",
  "部队士气低落": "fame-low.json",
  "任务威胁图谱": "task-threaten.json",
  "作战事理图谱": "fight.json",
  "军事行动轨迹图谱": "track.json",
  "边境巡逻军事行动轨迹图谱": "border.json",
  "边境巡逻": "border.json",
  "特种作战突袭军事行动轨迹图谱": "special-raid.json",
  "特种作战突袭": "special-raid.json",
  "防空作战军事行动轨迹图谱": "air-defense.json",
  "防空作战": "air-defense.json"
}

exports.getJsonFromFile = (filename) => {
  filename = filename.trim()
  return new Promise((resolve, reject) => {
    fs.readFile(path.join(dataFilePath, dataMap[filename]), 'utf8', (err, data) => {
      if (err) {
        return reject({ error: 'Failed to read data file' });
      }

      try {
        // 解析 JSON 数据
        const jsonData = JSON.parse(data);
        // 返回解析后的数据
        resolve(jsonData);
      } catch (parseError) {
        reject({ error: 'Failed to parse JSON data' });
      }
    });
  });
}